import {Node, Prefab, Vec3} from 'cc';
import {CombinationHandler} from "db://assets/Scripts/MVC/Bullet/CombinationHandler";
import {BulletController} from "db://assets/Scripts/MVC/Bullet/BulletController";
import {PoolManager} from "db://assets/Scripts/framework/PoolManager";

/**
 * M型子弹
 */
export class MPolicy implements CombinationHandler {

    /**
     * M型子弹
     *
     * @param bulletPrefab 子弹模型
     * @param parent 父节点
     * @param playerNode 玩家节点
     * @param speed 移动速度
     */
    combination(bulletPrefab: Prefab, parent: Node, playerNode: Node, speed: Vec3): Node[] {
        // 创建子弹节点列表
        const bulletNodes: Node[] = [];

        // 创建子弹节点
        const bulletNode = PoolManager.getInstance().getNode(bulletPrefab,parent);
        // 添加至子弹节点列表
        bulletNodes.push(bulletNode);

        // 设置初始位置
        const position = playerNode.position;
        bulletNode.setPosition(position.x, position.y, position.z - 1);

        // 设置攻击速度
        const bulletController: BulletController = bulletNode.getComponent(BulletController);
        bulletController.uiState.speed = speed;

        // 返回子弹节点列表
        return bulletNodes;
    }
}